<?php
/**
 * Created by PhpStorm.
 * User: lyh
 * Date: 2017/3/21
 * Time: 23:04
 */
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller{
    public function index(){
        $this->display();
    }

    public function verify(){
        $verify=new \Think\Verify();
        $verify->useImgBg = true;
        $verify->entry();
    }


    public function handleLogin(){
        if(IS_POST){
            $account=$_POST['account'];
            $password=$_POST['password'];
            $verify=$_POST['verify'];
            $Verify = new \Think\Verify;
            if(!$Verify->check($verify))
            {
                $this->error("验证码错误！");
                return;
            }
            $user=M('Admin')->where("account='%s'",$account)->field('id,username,password,status')->find();
            if(!$password || $user['password']!=$password){
                $this->error("账号或密码输入有误");
            }else if($user['status']=='0'){
                $this->error("该账号已被禁止使用");
            }else{
                session(C('USER_AUTH_KEY'),$user['id']);
                session('username',$user['username']);
                M('Admin')->where('id=%d',$user['id'])->setField('login_time',time());
                $this->redirect('admin/index/index',array('username'=>$user['username']));//跳转至后台首页
            }
        }
    }
}